import '../utils/TimeUtil.dart';

class NewsUgcData {
  String? ugcId; // 动态id
  String? title; // 动态标题
  String? content; // 动态内容
  List<String>? imageUrlList; // 图片url列表
  String? videoCover; // 视频封面
  String? userId; // 用户id
  double createTime; // 时间
  String? userNickname; // 用户名称
  int? state; // 动态类型
  int? mediaSizeType; // 媒体大小类型
  String? industryId; // 行业id
  String? industryName; // 行业名称
  String? occupationId; // 职业id
  String? occupationName; // 职业名称
  List<MentionUserDTO>? mentionUserDtoList; // @用户列表
  List<ForumDTO>? forumDtoList; // 论坛列表
  String get formattedTime => TimeUtil.getTimeAgo(createTime);

  NewsUgcData({
    this.ugcId,
    this.title,
    this.content,
    this.imageUrlList,
    this.videoCover,
    this.userId,
    required this.createTime,
    this.userNickname,
    this.state,
    this.mediaSizeType,
    this.industryId,
    this.industryName,
    this.occupationId,
    this.occupationName,
    this.mentionUserDtoList,
    this.forumDtoList,
  });

  // fromJson 方法
  factory NewsUgcData.fromJson(Map<String, dynamic> json) {
    return NewsUgcData(
      ugcId: json['ugcId'] as String?,
      title: json['title'] as String?,
      content: json['content'] as String?,
      imageUrlList: json['imageUrlList'] != null
          ? List<String>.from(json['imageUrlList'])
          : null,
      videoCover: json['videoCover'] as String?,
      userId: json['userId'] as String?,
      createTime: json['createTime']?.toDouble(),
      userNickname: json['userNickname'] as String?,
      state: json['state'] as int?,
      mediaSizeType: json['mediaSizeType'] as int?,
      industryId: json['industryId'] as String?,
      industryName: json['industryName'] as String?,
      occupationId: json['occupationId'] as String?,
      occupationName: json['occupationName'] as String?,
      mentionUserDtoList: json['mentionUserDtoList'] != null
          ? (json['mentionUserDtoList'] as List)
              .map((e) => MentionUserDTO.fromJson(e))
              .toList()
          : null,
      forumDtoList: json['forumDtoList'] != null
          ? (json['forumDtoList'] as List)
              .map((e) => ForumDTO.fromJson(e))
              .toList()
          : null,
    );
  }
}

class MentionUserDTO {
  String? userId; // 用户id
  String? nickname; // 用户名称
  String? petName; // 昵称

  MentionUserDTO({
    this.userId,
    this.nickname,
    this.petName,
  });

  // fromJson 方法
  factory MentionUserDTO.fromJson(Map<String, dynamic> json) {
    return MentionUserDTO(
      userId: json['userId'] as String?,
      nickname: json['nickname'] as String?,
      petName: json['petName'] as String?,
    );
  }
}

class ForumDTO {
  String? forumId; // 论坛id
  String? forumName; // 论坛名称

  ForumDTO({
    this.forumId,
    this.forumName,
  });

  // fromJson 方法
  factory ForumDTO.fromJson(Map<String, dynamic> json) {
    return ForumDTO(
      forumId: json['forumId'] as String?,
      forumName: json['forumName'] as String?,
    );
  }
}
